package com.example.developercalc;

import com.example.calculadoraprogramador.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
	  
	

public void potencia(View view){
	try{
	EditText editText1=(EditText)findViewById(R.id.editText1);
	double valor1=Double.parseDouble(editText1.getText().toString());
	EditText editText2=(EditText)findViewById(R.id.editText2);
	double valor2=Double.parseDouble(editText2.getText().toString());
	double resultado=Math.pow(valor1, valor2);
	
	AlertDialog.Builder resposta = new AlertDialog.Builder(this);
	resposta.setPositiveButton("OK", null);
	 resposta.setTitle("Resposta");
	 resposta.setMessage(String.valueOf(resultado));
	 resposta.show();}
	 catch(Exception e){
	     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Erro");
		 resposta.setMessage(e.getMessage());
		 resposta.show();}
		 }


public void xor(View view){
	try{
	EditText editText1=(EditText)findViewById(R.id.editText1);
	int valor1=Integer.parseInt(editText1.getText().toString());
	EditText editText2=(EditText)findViewById(R.id.editText2);
	int valor2=Integer.parseInt(editText2.getText().toString());
	int xor = valor1 ^ valor2;
	 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
	 resposta.setPositiveButton("OK", null);
	 resposta.setTitle("Resposta");
	 resposta.setMessage(String.valueOf(xor));
	 resposta.show();
	 }catch(Exception e){
	     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Erro");
		 resposta.setMessage(e.getMessage());
		 resposta.show();}
		 }
	


public void or(View view){
	try{
	EditText editText1=(EditText)findViewById(R.id.editText1);
	int valor1=Integer.parseInt(editText1.getText().toString());
	EditText editText2=(EditText)findViewById(R.id.editText2);
	int valor2=Integer.parseInt(editText2.getText().toString());
	int or=valor1|valor2;
	 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
	 resposta.setPositiveButton("OK", null);
	 resposta.setTitle("Resposta");
	 resposta.setMessage(String.valueOf(or));
	 resposta.show();
	}catch(Exception e){
	     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Erro");
		 resposta.setMessage(e.getMessage());
		 resposta.show();}
		 }


public void and(View view ){
	try{
	EditText editText1=(EditText)findViewById(R.id.editText1);
	int valor1=Integer.parseInt(editText1.getText().toString());
	EditText editText2=(EditText)findViewById(R.id.editText2);
	int valor2=Integer.parseInt(editText2.getText().toString());
	int and=valor1&valor2;
	 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
	 resposta.setPositiveButton("OK", null);
	 resposta.setTitle("Resposta");
	 resposta.setMessage(String.valueOf(and));
	 resposta.show();
	 } catch(Exception e){
	     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Erro");
		 resposta.setMessage(e.getMessage());
		 resposta.show();}
		 }
	
	

public void not(View view ){
	try{
	EditText editText1=(EditText)findViewById(R.id.editText1);
	int valor1=Integer.parseInt(editText1.getText().toString());
	
	int not=(valor1*(-1)-1);
	 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
	 resposta.setPositiveButton("OK", null);
	 resposta.setTitle("Resposta");
	 resposta.setMessage(String.valueOf(not));
	 resposta.show();
	 }catch(Exception e){
     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
	 resposta.setPositiveButton("OK", null);
	 resposta.setTitle("Erro");
	 resposta.setMessage(e.getMessage());
	 resposta.show();
	 }
	
}


      
public void mdc(View view){
	try{
	EditText editText1=(EditText)findViewById(R.id.editText1);
	int valor1=Integer.parseInt(editText1.getText().toString());
	EditText editText2=(EditText)findViewById(R.id.editText2);
	int valor2=Integer.parseInt(editText2.getText().toString());
	 int mod;
     int aux1, aux2 = 0;

     mod = valor1 % valor2;
     aux1 = valor2;
     while (mod != 0) {

         aux2 = mod;
         mod = aux1 % mod;
         aux1 = aux2;

     }
     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
	 resposta.setPositiveButton("OK", null);
	 resposta.setTitle("Resposta");
	 resposta.setMessage(String.valueOf(aux2));
	 resposta.show();
	 }catch(Exception e){
		 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Erro");
		 resposta.setMessage(e.getMessage());
		 resposta.show();
	 }
}
	

public void fi_chamada(View  view){
	try{
	EditText editText1=(EditText)findViewById(R.id.editText1);
	int valor1=Integer.parseInt(editText1.getText().toString());
	
	 int valor_array = (valor1);
     int conjunto[] = new int[valor_array];
   
     String resultado = "";
     int cont = 0;
     int cont2 = 0;
     for (int i = 0; i < valor_array; i++) {
         conjunto[i] = cont++;
         if (Funcoes.mdc2(String.valueOf(conjunto[i]), String.valueOf(valor1)) == 1) {
             resultado += conjunto[i] + " ";
             cont2++;
             System.out.println(resultado);
         }
     }

     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
	 resposta.setPositiveButton("OK", null);
	 resposta.setTitle("Resposta");
	 resposta.setMessage(String.valueOf(cont2+" quantidade de elementos inversiveis "));
	 resposta.show();
	 }catch(Exception e){
		 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Erro");
		 resposta.setMessage(e.getMessage());
		 resposta.show();
	 }
     
}

	


	
	public void soma(View view){
		try{
		EditText editText1=(EditText)findViewById(R.id.editText1);
		int valor1=Integer.parseInt(editText1.getText().toString());
		EditText editText2=(EditText)findViewById(R.id.editText2);
		int valor2=Integer.parseInt(editText2.getText().toString());
		 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Resposta");
		 resposta.setMessage(String.valueOf(Aritmeticos.soma(valor1, valor2)));
		 resposta.show();
		 }catch(Exception e){
		     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
			 resposta.setPositiveButton("OK", null);
			 resposta.setTitle("Erro");
			 resposta.setMessage(e.getMessage());
			 resposta.show();
			 }
	}
		
	
	
	public void subtracao(View view){
		try{
		EditText editText1=(EditText)findViewById(R.id.editText1);
		int valor1=Integer.parseInt(editText1.getText().toString());
		EditText editText2=(EditText)findViewById(R.id.editText2);
		int valor2=Integer.parseInt(editText2.getText().toString());
		
		 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Resposta");
		 resposta.setMessage(String.valueOf(Aritmeticos.subtracao(valor1, valor2)));
		 resposta.show();
		}catch(Exception e){
		     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
			 resposta.setPositiveButton("OK", null);
			 resposta.setTitle("Erro");
			 resposta.setMessage(e.getMessage());
			 resposta.show();
			 }
		
   }
	
	
	public void multiplicacao(View view){
		try{
		EditText editText1=(EditText)findViewById(R.id.editText1);
		int valor1=Integer.parseInt(editText1.getText().toString());
		EditText editText2=(EditText)findViewById(R.id.editText2);
		int valor2=Integer.parseInt(editText2.getText().toString());
		 AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Resposta");
		 resposta.setMessage(String.valueOf(Aritmeticos.multiplicacao(valor1, valor2)));
		 resposta.show();
		}catch(Exception e){
		     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
			 resposta.setPositiveButton("OK", null);
			 resposta.setTitle("Erro");
			 resposta.setMessage(e.getMessage());
			 resposta.show();
			 }
			 
		
	}
	
	public void divisao(View view){
		try{
	
		EditText editText1=(EditText)findViewById(R.id.editText1);
		int valor1=Integer.parseInt(editText1.getText().toString());
		EditText editText2=(EditText)findViewById(R.id.editText2);
		int valor2=Integer.parseInt(editText2.getText().toString());
		
		AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Resposta");
		 resposta.setMessage(String.valueOf(Aritmeticos.divisao(valor1, valor2)));
		 resposta.show();
	} catch(Exception e){
		     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
			 resposta.setPositiveButton("OK", null);
			 resposta.setTitle("Erro");
			 resposta.setMessage(e.getMessage());
			 resposta.show();
			 }
			 
	}
	public void mod(View view) {
		try{
		EditText editText1=(EditText)findViewById(R.id.editText1);
		int valor1=Integer.parseInt(editText1.getText().toString());
		EditText editText2=(EditText)findViewById(R.id.editText2);
		int valor2=Integer.parseInt(editText2.getText().toString());
		
		AlertDialog.Builder resposta = new AlertDialog.Builder(this);
		 resposta.setPositiveButton("OK", null);
		 resposta.setTitle("Resposta");
		 resposta.setMessage(String.valueOf(valor1%valor2));
		 resposta.show();
		 }catch(Exception e){
		     AlertDialog.Builder resposta = new AlertDialog.Builder(this);
			 resposta.setPositiveButton("OK", null);
			 resposta.setTitle("Erro");
			 resposta.setMessage(e.getMessage());
			 resposta.show();
			 
			 }
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
